package com.lpw.dbvideo.video.controller;

import com.lpw.dbvideo.video.domain.Video;
import com.lpw.dbvideo.video.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/api/video")
public class VideoController {

    @Autowired
    private VideoService videoService;

    /**
     * 分页查询
     *
     * @param pageNum 页数，默认为第一页
     * @param pageSize 每页显示的数量，默认为10条
     * @return
     */
    @GetMapping("page")
    public Object pageVideo(@RequestParam(value = "page", defaultValue = "1") int pageNum,@RequestParam(value = "size", defaultValue = "10") int pageSize) {
        return videoService.findAll(pageNum,pageSize);
    }

    /**
     * 根据id查询video
     * @param videoId
     * @return
     */
    @GetMapping("findById")
    public Object findById(@RequestParam(value = "video_id", required = true) int videoId) {
        System.err.println("video====");
        return videoService.findById(videoId);
    }

    /**
     * 根据id删除video
     *
     * @param videoId
     * @return
     */
    @DeleteMapping("deleteById")
    public Object deleteById(@RequestParam(value = "video_id", required = true) int videoId) {
        return videoService.delet(videoId);
    }

    /**
     * 根据id更新video
     * @param video
     * @return
     */
    @PutMapping("updateById")
    public Object update(@RequestBody Video video) {
        System.err.println(video);
        return videoService.update(video);
    }

    /**
     * 新增视频
     *
     * @param video
     * @return
     */
    @PostMapping("save")
    public Object save(@RequestBody Video video) {
        return videoService.save(video);
    }
}
